package com.dfbz.demo01_卖票案例;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Ticket implements Runnable {

    //票数
    private Integer ticket = 10000;

    private Object obj = new Object();

    @Override
    public void run() {

        while (true) {
            synchronized (obj){
                if (ticket <= 0) {
                    break;      //票卖完了
                }
                System.out.println(Thread.currentThread().getName() + "正在卖第: " + (10001 - ticket) + "张票");
                ticket--;
            }
        }
    }
}